package com.speedchina.common.message.email.config;

import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.stereotype.Component;

/**
 * @author zyw
 *
 *  126邮箱SMTP服务器地址:smtp.126.com,端口号:465或者994
    163邮箱SMTP服务器地址:smtp.163.com,端口号:465或者994
    yeah邮箱SMTP服务器地址:smtp.yeah.net,端口号:465或者994
    qq邮箱SMTP服务器地址：smtp.qq.com,端口号465或587*
 */
@ConfigurationProperties(prefix ="speedchina.message.mail")
@Data
@Configuration
public class MailConfig{

    @Bean
    public JavaMailSenderImpl JavaMailSender(){
        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
        mailSender.setHost(this.host);
        mailSender.setUsername(this.username);
        mailSender.setPassword(this.password);
        return  mailSender;
    }
    /**
     * 配置 SMTP 服务器地址
     */
    @Value("${host:}")
    public String host;
    /**
     * 发送者邮箱
     */
    @Value("${username:}")
    public String username;
    /**
     * 配置密码，注意不是真正的密码，而是刚刚申请到的授权码
     */
    @Value("${password:}")
    public String password;
    /**
     * 端口号
     */
    @Value("${port:}")
    public String port;

    /**
     * 抄送邮箱账号 可以多个配置用";"隔开
     */
    private String cc;
    /**
     * 收信箱邮箱账号 可以多个配置用";"隔开
     */
    private String toMailAddr;

}
